package movie.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import movie.entity.Consumer;
import movie.service.RegisterService;

@Controller
public class RegisterController {
	@Autowired
	private RegisterService registerService;
	@GetMapping("/check")
	public @ResponseBody int check(String email) {
		
		int result = registerService.checkByEmail(email);
		
		return result;
	}
	
	@RequestMapping(value = "/register", method = RequestMethod.GET)
	public String get() {
		return "/user/register";
	}
	
	@RequestMapping(value = "/register", method = RequestMethod.POST)
	public String post(Consumer consumer) {
		int rows = registerService.Register(consumer);
		
		if(rows==1) {//成功
			return "/user/login";
		}
		else {//未注册成功
			return "/user/register";
		}
		//forward
	}
	
	
}
